export default {
  data() {
    return {
      selfAdaptionStyle: {}
    }
  },
  created() {
    let timer = null
    window.onresize = () => {
      clearTimeout(timer)
      timer = setTimeout(() => {
        const { transform, transformOrigin } = this.handleSelfAdaption()
        this.$set(this.$root.selfAdaptionStyle, 'transform', transform)
        this.$set(this.$root.selfAdaptionStyle, 'transformOrigin', transformOrigin)
      }, 600)
    }
    const { transform, transformOrigin } = this.handleSelfAdaption()
    this.$set(this.$root.selfAdaptionStyle, 'transform', transform)
    this.$set(this.$root.selfAdaptionStyle, 'transformOrigin', transformOrigin)
  },
  methods: {
    handleSelfAdaption(dw = 3840, dh = 2160) {
      const hScale = window.innerHeight / (dh || 1080)
      const wScale = window.innerWidth / (dw || 1920)
      return {
        transform: `scaleX(${wScale}) scaleY(${hScale})`,
        transformOrigin: `0 0`
      }
    },
    transPercent(percent) {
      const num = percent * 100
      return num.toFixed(2) + '%'
    }
  }
}
